<?php
namespace Home\Model;

use Think\Model;
class RegionModel extends Model
{   
    private $place ;
    /*
     * 获取一条信息的地址信息
     * @param $arr  array (province,city,country)
     */
    public function getMessagePlace($arr){
       $arr  =is_array($arr)?$arr:array($arr);
       $place  =$this->where(array('region_id'=>array('in',$arr)))->select();
        if(empty($place)) return null;
        foreach($place as $k=>$v){
           $place[$v['region_id']] =$v;
           unset($place[$k]);
        } 
        return $place;
    } 
    
    /**初始化**/
    public function getInitPlace($provice=1,$city=0,$country=0){
        $this->place['province'] = $this->where(array('parent_id'=>$provice))->select();
       
        $this->place['city'] =  $this->where(array('parent_id'=>$this->place['province'][0]['region_id']))->select();
        $this->place['country'] = $this->where(array('parent_id'=>$this->place['city'][0]['region_id']))->select();
      //  print_r($this->place);
        return $this->place;
    }
}